home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / Softshoe / Lisa's Mac Parts / Events / Quitter.cp < prev    next >
Text File  |  2000-06-23  |  1KB  |  60 lines

  1. // Quitter.cp
  2.  
  3. #ifndef Quitter_h
  4. #include "Quitter.h"
  5. #endif
  6. #ifndef QuitBlocker_h
  7. #include "QuitBlocker.h"
  8. #endif
  9. #ifndef BroadcastLoop_h
  10. #include "BroadcastLoop.h"
  11. #endif
  12. #ifndef PreparingToQuit_h
  13. #include "PreparingToQuit.h"
  14. #endif
  15.  
  16. Quitter::Quitter()
  17.   : quitting( false ),
  18.      savingOption( SavingOption::ask )
  19.   {
  20.   }
  21.  
  22. Quitter& Quitter::The()
  23.   {
  24.     static Quitter the;
  25.     return the;
  26.   }
  27.  
  28. bool Quitter::CanStartQuitting() const
  29.   {
  30.     return quitting == false && QuitBlocker::AllowsQuit();
  31.   }
  32.  
  33. bool Quitter::CanStopQuitting() const
  34.   {
  35.     return quitting == true;
  36.   }
  37.  
  38. void Quitter::StartQuitting( SavingOption theSavingOption )
  39.   {
  40.     Assert( CanStartQuitting() );
  41.     savingOption = theSavingOption;
  42.     quitting = true;
  43.   }
  44.  
  45. void Quitter::StopQuitting()
  46.   {
  47.     Assert( CanStopQuitting() );
  48.     quitting = false;
  49.   }
  50.  
  51. bool Quitter::ApplicationCanExit() const
  52.   {
  53.     for ( BroadcastLoop<PreparingToQuit> receiver( PreparingToQuit::TheBroadcaster() );
  54.             quitting && QuitBlocker::AllowsQuit() && receiver.Unfinished();
  55.             receiver++ )
  56.         receiver->PrepareToQuit( savingOption );
  57.     
  58.     return quitting && QuitBlocker::AllowsQuit();
  59.   }
  60.